package com.fresh.mapper;

import com.fresh.annotation.AutoFill;
import com.fresh.dto.UserPageQueryDTO;
import com.fresh.enumeration.OperationType;
import com.fresh.pojo.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author Long
 * @title UserMapper
 * @date 2024/07/01 19:34
 * @description TODO
 */

@Mapper
public interface UserMapper {

    /**
     * 用户登陆验证
     * @param userName
     * @return
     */
    @Select("select * from fresh_everyday.fresh_user where user_name = #{userName} and status = 1")
    User getUserByUserName(String userName);


    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into fresh_everyday.fresh_user (id, user_name, password, email, status, create_time, update_time, sex) " +
            "values (#{id}, #{username}, #{password}, #{email}, #{status}, #{createTime}, #{updateTime}, #{sex})")
    @AutoFill(value = OperationType.INSERT)
    void insertUser(User user);

    /**
     * 用户分页查询
     * @param userPageQueryDTO
     * @return
     */
    Page<User> query(UserPageQueryDTO userPageQueryDTO);

    /**
     * 用户信息修改
     * @param user
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(User user);

}
